package com.superteam.zzl.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.view.ViewGroup;

import com.superteam.zzl.activity.R;
import com.superteam.zzl.activity.databinding.ActivityInfoItemvpVpBinding;
import com.superteam.zzl.model.DynamicFragment.bean.Group;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/14.
 */

public class InfoActivityVpAdapter extends BasePagerAdapter<Group.DataBean.GroupListBean> {

    private ActivityInfoItemvpVpBinding vpBinding;

    public InfoActivityVpAdapter(Context context, List<Group.DataBean.GroupListBean> list) {
        super(context, list);
    }

    @Override
    public int getCount() {
        int size = list.size();
        if (list == null || size == 0) {
            return 0;
        } else {
            if (size % 4 == 0) {
                return size / 4;
            } else {
                return size / 4 + 1;
            }
        }
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        vpBinding = DataBindingUtil.inflate(inflater, R.layout.activity_info_itemvp_vp, container, false);
        List<Group.DataBean.GroupListBean> been = new ArrayList<>();
        Group.DataBean.GroupListBean groupListBean = list.get(0);
        int temp = position * 4;
        if (position != getCount() - 1) {
            for (int i = temp; i <temp + 4; i++) {
                been.add(list.get(temp));
            }
        } else {
            for (int i = temp; i < list.size(); i++) {
                been.add(list.get(temp));
            }
        }
        vpBinding.gv.setAdapter(new InfoActivityVpGvAdapter(context, been, R.layout.activity_info_itemvp_vp_gv));
        vpBinding.executePendingBindings();
        datas[position] = vpBinding;
        container.addView(vpBinding.getRoot());
        return vpBinding.getRoot();
    }

}
